#ifndef PLINTH_SIMPLEIMAGE_H
#define PLINTH_SIMPLEIMAGE_H

#include <string>

typedef unsigned char UCHAR;

class SimpleImage
{
public:
	SimpleImage();
	SimpleImage(const SimpleImage& rhs);
	~SimpleImage();

	//GET_SELF
	//SimpleImage* op = pop_custom<SimpleImage>(L, 1, "SimpleImage");

	//CALL_PREFIX
	//op->

	//PUSH_FUNC UCHAR
	//lua_pushnumber(L, ret);

	//POP_FUNC UCHAR
	//UCHAR a%(argPos)d = (UCHAR)lua_tonumber(L, %(luaPos)d);

	void deepCopy(const SimpleImage& rhs);
	//LIAG_THESE
	void allocateLayered(int sx, int sy, int sc);
	void allocateInterleaved(int sx, int sy, int sc);
	void deallocate();
	void untether();
	SimpleImage clone();

	UCHAR rawGet(int pos);
	UCHAR get(int x, int y, int c);

	void rawSet(int pos, UCHAR val);
	void set(int x, int y, int c, UCHAR val);

	int rawPos(int x, int y, int c);

	//SPECIAL_NAME __gc
	void deleteThis();

	int sizeX();
	int sizeY();
	int sizeC();
	int size();

	int getmx();
	int getmy();
	int getmc();
	int getb();
	//STOP_LIAG
	int toBytes(unsigned char* dest, int destsize);
	void fromBytes(unsigned char* src, int srcsize);
	std::string toStdString();
	void fromStdString(std::string src);

	void getBounds(int& x1, int& y1, int& width, int& height, UCHAR thresh, int chan);

	UCHAR* getPtr();

private:
	UCHAR* _data;
	int* _dataRefCt;
	int _datasize;

	int _sizeX;
	int _sizeY;
	int _sizeC;
	int _multX;
	int _multY;
	int _multC;
	int _b;
};

#endif